package com.yanchangapp.adapter._n_manage;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.model.bean.WorkItemBean;

import java.util.List;

/**
 * Created by apple on 2019-10-10.
 * description: 工作项列表Adapter...
 */
public class WorkItemListAdapter extends BaseQuickAdapter<WorkItemBean, BaseViewHolder> {
    private boolean isEditType = false;

    public WorkItemListAdapter(@Nullable List<WorkItemBean> data) {
        super(R.layout.item_work_item_list, data);
    }

    public void setEditType(boolean isEditType){
        this.isEditType = isEditType;
    }


    @Override
    protected void convert(BaseViewHolder helper, WorkItemBean item) {
        RelativeLayout rlEdit = helper.getView(R.id.rlEditStyle);
        CheckBox checkBox =  helper.getView(R.id.checkbox);
        if (isEditType){
            rlEdit.setVisibility(View.VISIBLE);
            checkBox.setChecked(item.isSelected);
        }else {
            rlEdit.setVisibility(View.GONE);
        }
        helper.setText(R.id.tvItemName,item.getTitle());
        helper.addOnClickListener(R.id.checkbox).addOnClickListener(R.id.llTime);

        if (item.getTime() == null){
            helper.setText(R.id.tvTime,"期限");
        }else{
            helper.setText(R.id.tvTime,item.getTime()+"天");
        }
    }
}
